#include "CEC2017_F9.h"

namespace Solver
{

CEC2017_F9::CEC2017_F9(std::size_t dim):BaseTestFun(dim, FunType_E::CEC2017_F9_E, DifficultyLevel_E::Easy_E, "CEC2017_F6", "")
{
    passY_ = 1e-12;
    bestY_ = 0;
    std::fill(bestX_.begin(), bestX_.end(), 1);
}

CEC2017_F9::~CEC2017_F9()
{

}

value_t CEC2017_F9::calcMinFun(const VectorXd_t &x)
{
    //1.
    std::size_t num = x.size();
    if (num == 0)
    {
        return 0;
    }

    //2.
    value_t sum(std::pow(std::sin(M_PI * wFun(x[0])), 2)), wi;
    --num;
    for (std::size_t i = 0; i != num; ++i)
    {
        wi   = wFun(x[i]);
        sum += std::pow(wi - 1, 2) * (1 + 10 * std::pow(std::sin(M_PI * wi + 1), 2));
    }

    //3.
    wi   = wFun(x[num]);
    sum += std::pow(wi - 1, 2) * (1 + std::pow(std::sin(2 * M_PI * wi), 2));
    return sum;
}

value_t CEC2017_F9::wFun(value_t x) const
{
    return 1 + (x - 1) / 4;
}

}